switchroot: Document a bit more, add demo shell implementation
authorFrancesco Giannelli <bassobassista@gmail.com>
Fri, 7 Apr 2017 20:58:55 +0000 (22:58 +0200)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 19 Apr 2017 18:52:05 +0000 (18:52 +0000)
This could help others who want to integrate with other init
systems/initramfs.

Commit-message-by: Colin Walters <walters@verbum.org>
Closes: #784
Approved by: cgwalters

docs/manual/adapting-existing.md
src/switchroot/switchroot.sh [new file with mode: 0644]

index 275479f03010cd4e2299b266e7b7e89ec97d0452..687f501bf1a4a42c29261a83a485d9e6f7d7a761 100644 (file)
@@ -71,17 +71,23 @@ directory.
 
 ## Booting and initramfs technology
 
-OSTree comes with optional dracut+systemd integration code that parses
-the `ostree=` kernel command line argument in the initramfs, and then
-sets up the read-only bind mount on `/usr`, a bind mount on the
-deployment's `/sysroot` to the physical `/`, and then finally uses
-`mount(MS_MOVE)` to make the deployment root appear to be the root
-filesystem before telling systemd to switch root.
+OSTree comes with optional dracut+systemd integration code which follows
+this logic:
+
+- Parse the `ostree=` kernel command line argument in the initramfs
+- Set up a read-only bind mount on `/usr`
+- Bind mount the deployment's `/sysroot` to the physical `/`
+- Use `mount(MS_MOVE)` to make the deployment root appear to be the root filesystem
+
+After these steps, systemd switches root.
 
 If you are not using dracut or systemd, using OSTree should still be
-possible, but you will have to write the integration code.  Patches to
-support other initramfs technologies and init systems, if sufficiently
-clean, will likely be accepted upstream.
+possible, but you will have to write the integration code. See the
+existing sources in [src/switchroot](/src/switchroot) as a reference,
+as well as [src/switchroot/switchroot.sh](/src/switchroot/switchroot.sh).
+
+Patches to support other initramfs technologies and init systems, if
+sufficiently clean, will likely be accepted upstream.
 
 A further specific note regarding `sysvinit`: OSTree used to support
 recording device files such the `/dev/initctl` FIFO, but no longer
diff --git a/src/switchroot/switchroot.sh b/src/switchroot/switchroot.sh
new file mode 100644 (file)
index 0000000..64de80c
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# This demonstration script is an implementation in shell
+# similar to ostree-prepare-root.c.  For a bit more information,
+# see adapting-existing.md.
+
+## the ostree boot parameter is avaialbe during the init
+env | grep ostree
+# ostree=/ostree/boot.1/.../.../0
+## bind mount the ostree deployment to prepare it for move
+mount --bind $sysroot$ostree $sysroot$ostree
+## bind mount read-only /usr
+mount --bind $sysroot$ostree/usr $sysroot$ostree/usr
+mount --bind -o remount,ro $sysroot$ostree/usr $sysroot$ostree/usr
+## bind mount the physical root
+mount --bind $sysroot $sysroot$ostree/sysroot
+## bind mount the var directory which is preserved between deployments
+mount --bind $sysroot/ostree/deploy/os/var $sysroot$ostree/var
+## make sure target directories are present within var
+cd $sysroot$ostree/var
+mkdir -p roothome mnt opt home
+cd -
+## move the deployment to the sysroot
+mount --move $sysroot$ostree $sysroot
+## after these the init system should start the switch root process